from graphics import *

W = 640
H = 640
A = 100
COUNT_H = 4
COUNT_V = 4
COUNT = COUNT_H * COUNT_V

def draw_tab(offset, styles, draw):
    hgap = int((W - COUNT_H*A)/(COUNT_H+1))
    vgap = int((H - COUNT_V*A)/(COUNT_V+1))
    i = 0
    while i < COUNT and offset + i < len(styles):
        x = hgap + (i%COUNT_H) * (hgap + A)
        y = vgap + int(i/COUNT_H) * (vgap + A)
        draw(x, y, styles[offset + i])
        draw_text(x + A/2, y+A, styles[offset + i].name, A_CENTER, A_TOP, C_WHITE)
        i += 1
        
def screen(title, styles, draw):
    tabs = 1+int((len(styles)-1)/COUNT)
    for t in range(0, tabs):
        if tabs > 1:
            ct = "%s (%d/%s)"%(title, t+1, tabs)
        else:
            ct = title
        clear(C_BLACK)
        draw_text(W/2, 0, ct, A_CENTER, A_TOP, C_WHITE)
        draw_tab(t*COUNT, styles, draw)
        draw_text(W/2, H, "Press any key to continue...", A_CENTER, A_BOTTOM, C_WHITE)
        read_key()

def paint_color(x, y, color):
    set_color(color)
    draw_rect(x,y,A,A)
    if color is C_BLACK:
        set_color(C_WHITE)
        draw_rect(x,y,A,A, fill = False)

def paint_line(x, y, style):
    set_line_style(1, style)
    set_color(C_WHITE)
    draw_line(x,y+A/2,x+A,y+A/2)
    draw_line(x+A/2,y,x+A/2,y+A)

def paint_fill(x, y, style):
    set_color(C_WHITE)
    set_fill_style(style)
    draw_rect(x,y,A,A)
    set_fill_style(FILL_SOLID)


init(W, H, title="Graphics constants")

screen("Colors", COLORS, paint_color)
screen("Line Styles", LINE_STYLES, paint_line)
screen("Fill Styles", FILL_STYLES, paint_fill)




